<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

namespace core;
use think\exception\ClassNotFoundException;
class Loader{
    
    
    private $helperClass;
    private static $classList;   // 操作对象列表
    
    public function __construct($helperClass){
        $helperClass = $helperClass.'Data';
        $this->helperClass = $helperClass;
        $class = $helperClass;
        if (!isset(self::$classList[$this->helperClass])){
            if (class_exists($class)) {
                $model = new $class();
            } else {
                throw new ClassNotFoundException('class not exists:' . $class, $class);
            }         
            self::$classList[$this->helperClass] = $model;   
        }
    }    
    
    
    /**
     * 利用__call方法实现一些特殊的Model方法
     * @access public
     * @param string $method 方法名称
     * @param array $args 调用参数
     */
    public function __call($method,$args){  
        $this->setLog($method,$args); // 保存执行的日志
        if(method_exists(self::$classList[$this->helperClass], $method)){
            return call_user_func_array(array(self::$classList[$this->helperClass],$method), $args);
        }else{
            logicE($method.'方法不存在');
        }
    }
    
    /**
     * 设置执行日志
     */
    private function setLog(){
        
    }
}